package com.taobao.shopcart.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.taobao.shopcart.model.po.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 订单Mapper接口
 */

@Mapper
public interface OrdersMapper extends BaseMapper<Orders> {
//
//    /**
//     * 关注页店铺预览
//     */
//    @Select("SELECT store_id, store_name, store_icon, remark, title, label, release_time, img_list, buy_num, look_num FROM stores WHERE 1 =1 LIMIT #{pageNo}, #{pageSize}")
//    List<StorePreview> queryPreview(@Param("pageNo") Long pageNo, @Param("pageSize") Long pageSize);
//
    /**
     * 查询未支付订单
     */
    @Select("SELECT order_id, user_id, created_at from orders WHERE status = 0")
    List<Orders> selectOrderStatus();

    /**
     * 查询个人未支付订单
     */
    @Select("SELECT order_id, user_id, created_at from orders WHERE status = 0 and user_id = #{userId}")
    List<Orders> selectOrderStatusByUserId(@Param("userId") int userId);

    /**
     * 获取待发货订单
     */
    @Select("SELECT order_id, user_id, created_at from orders WHERE status = 1 and user_id = #{userId}")
    List<Orders> selectOrderStatusByShipped(@Param("userId") int userId);

    /**

    /**
     * 根据订单id查询
     */
    @Select("SELECT * from orders WHERE order_id = #{orderId}")
    Orders selectByOrderId(@Param("orderId") long orderId);

    /**
     * 用户id获取
     */
    @Select("select * from orders where user_id=#{userId}")
    List<Orders> queryOrder(@Param("userId") int userId);

    /**
     * 根据用户id查询
     */
    @Select("SELECT * from orders WHERE user_id = #{userId}")
    List<Orders> selectAllByUserId(@Param("userId") int userId);

    /**
     * 根据订单id更新 status upDateAt
     */
    @Update("UPDATE orders SET status = #{status}, updated_at = #{updatedAt} WHERE order_id = #{orderId}")
    int updateByOrderId(@Param("orderId") long orderId, @Param("status") int status, @Param("updatedAt") LocalDateTime updatedAt);

}
